Skip to content

[codegen] migrate stdlib/crypto to emitsymbol/emitoperand helpers#648

Merged
cs01 merged 2 commits intomainfrom
step2-wave3-stdlib
Apr 22, 2026
Merged

[codegen] migrate stdlib/crypto to emitsymbol/emitoperand helpers#648
cs01 merged 2 commits intomainfrom
step2-wave3-stdlib

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 21, 2026

Before

stdlib/crypto.ts built LLVM IR via raw ctx.emit() template-literal strings, hardcoding @func symbols and i8* %tmp operands throughout every hash/hmac/pbkdf2/uuid helper.

After

No user-facing change. Internal refactor only. Symbol/operand formatting now flows through emitSymbol(name, "@") and emitOperand(value, type) helpers at every call site. Raw ctx.emit() is retained for the call/GEP/load/store/bitcast skeleton to preserve exact pre-migration IR (see Description).

Description

Continues Step 2 of #640. Third wave after PR #645 (math/process) and PR #647 (console/date).

Scope matches Step 2's intent: only emitSymbol/emitOperand helpers. An initial version of this PR also migrated emitCall/emitCallVoid/emitGep/emitLoad/emitStore/emitBitcast (structured IR builders). Those broke stage2 arrays/array-isarray self-hosting on CI — crypto.ts is linked into src/chad-native.ts, so a miscompile of crypto codegen corrupts the stage1 compiler which then silently miscompiles unrelated fixtures. See #649. Structured-builder migration is deferred until the root cause in those helpers is investigated.

Fixes #649.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Place
Binary Trees 1.071s 0.944s 2.064s 0.972s 🥇
Cold Start 1.4ms 0.7ms 0.9ms 22.2ms 🥇
Fibonacci 0.709s 0.707s 1.349s 2.647s 🥇
Hash Map Lookup 0.077s 0.057s 0.073s 0.095s 🥇
JSON Parse/Stringify 0.028s 0.041s 0.122s 0.099s 🥈
Monte Carlo Pi 0.341s 0.348s 0.355s 2.010s 🥈
N-Body Simulation 1.383s 1.750s 1.777s 1.864s 🥈
Regex Match 0.012s 0.004s 0.018s 0.003s 🥈
SQLite 0.032s 0.269s 0.348s 0.334s 🥈
File I/O 0.071s 0.075s 0.071s 0.139s 🥉
Quicksort 0.191s 0.218s 0.188s 0.232s 🥉
Sieve of Eratosthenes 0.011s 0.021s 0.015s 0.033s 🥉
String Manipulation 0.006s 0.014s 0.013s 0.031s 🥉
Matrix Multiply 0.380s 0.484s 0.413s 0.331s #4

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.473s 0.721s 0.108s 🥈
Recursive Grep 0.017s 0.008s 0.084s 🥈

structured ir builders (emitcall/emitgep/emitbitcast/emitload/emitstore/emitcallvoid)
caused stage2 array-isarray miscompile on ci. revert them to inline emit() per
step 2 wave 3 intent. only emitsymbol/emitoperand wrappers remain, matching
console/date pattern from pr #647.

fixes #649
@cs01 cs01 merged commit 425d51e into main Apr 22, 2026
13 checks passed
@cs01 cs01 deleted the step2-wave3-stdlib branch April 22, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[codegen] crypto.ts migration to emitCall/emitCallVoid/emitGep breaks stage1/2 array-isarray

1 participant